package com.glebusheg.client
{
	import com.ek.asset.AssetLoader;
	import flash.utils.ByteArray;
	import flash.utils.getTimer;
	
	/**
	 * @author eliasku
	 */
	public class RpcInitialize extends RpcCall
	{
		private var _randomSeed:int;
		private var _timeStamp:int;
		private var _dateStamp:Date = new Date();
		
		public function RpcInitialize()
		{
			super(RpcType.INITIALIZE);
			
			if (!url)
			{
				var ba:ByteArray = new ByteArray();
				var data:Object = RpcFakeUtil.createInitialize();
				
				ba.writeObject(data);
				
				fakeResponse = ba;
				fakeResponse.position = 0;
			}
			
			var object:Object = { };
			
			var failedLoaders:Array = AssetLoader.failedLoaders;
			if (failedLoaders.length > 0)
				object.failed_loaders = failedLoaders;
			
			requestObject = object;
		}
		
		protected override function onComplete():void
		{
			if (isSuccess && responseObject)
			{
				if (responseObject.hasOwnProperty("randomSeed"))
					_randomSeed = responseObject.randomSeed;
				if (responseObject.hasOwnProperty("date"))
					_dateStamp = new Date(responseObject.date * 1000);
				
				_timeStamp = getTimer();
			}
		}
	}
}

